#ifndef QQ_CHAT_CONTROLLER
#define QQ_CHAT_CONTROLLER

#include <qfile.h>
#include <qjsonobject.h>
#include <qobject.h>
#include <QtConcurrent>

#include "api/QQVLCApi.h"

#include "core/QQSettings.h"

#include "network/QQNetWork.h"

#include "main/QQClientView.h"

#include "chat/QQChatView.h"
#include "chat/audio/QQRTCAudioEngineFactory.h"
#include "chat/video/QQRTCVideoEngineFactory.h"

class QQChatController : public QObject
{
	Q_OBJECT
public:
	QQChatController(QQClientView* parent = nullptr);
	~QQChatController();

	void doReadyRead(const QJsonObject& data);
signals:
	void updateFileProgress(const QString& filename, int progress);
public slots:
	void doMousePress(QPoint pos, Qt::MouseButton type);
	void doHandleNetworkMessage(const QString& account, const QString& message);
private:
	void doLoadMessages(const QString& account);
	void doLoadEmojiData(const QString& account);

	void doCheckPicture(const QString& account, const QStringList& filenames);
	void doCheckFile(const QString& account, const QStringList& filenames);
	void doSendFile(const QString& account, const QStringList& filenames);
	void doSendFile(const QString& account, const QString& filename, const QList<int>& indexs);
	void doSendMessage(const QString& account, const QString& message);

	void doChangeAudioMicrophoneState(bool opened);
	void doSendRealCommunicateAudio(const QString& account);
	void doRefuseRealCommunicateAudio(const QString& account);
	void doRealCommunicateAudioError(int detail);

	void doReceiveRealCommunicateAudio(const QString& account);
	void doAcceptRealCommunicateAudioByMe(const QString& account);
	void doRefuseRealCommunicateAudioByMe(const QString& account);

	void doStartRealCommunicateAudio(const QVariantMap& info);
	void doStopRealCommunicateAudio(const QVariantMap& info);

	void doChangeVideoMicrophoneState(bool opened);
	void doChangeVideoCameraState(bool opened);
	void doSendRealCommunicateVideo(const QString& account);
	void doRefuseRealCommunicateVideo(const QString& account);
	void doRealCommunicateVideoError(int detail);

	void doReceiveRealCommunicateVideo(const QString& account);
	void doAcceptRealCommunicateVideoByMe(const QString& account);
	void doRefuseRealCommunicateVideoByMe(const QString& account);

	void doStartRealCommunicateVideo(const QVariantMap& info);
	void doStopRealCommunicateVideo(const QVariantMap& info);
private:
	QQChatView* mChatView;
	QQRTCAudioEngine* mAudioEngine;
	QQRTCVideoEngine* mVideoEngine;
};


#endif // !QQ_CHAT_CONTROLLER


